﻿using Dx.DDD.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Dx.DDD.Domain
{
    //public interface IMySqlRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>
    public interface IRepository<TEntity, TKey> where TEntity : class, IEntity<TKey>
    {
        public  IQueryable<TEntity> WhereIf(bool condition, Expression<Func<TEntity, bool>> predicate);
        Task<TEntity?> FindAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = true, CancellationToken cancellationToken = default(CancellationToken));
        public Task<TEntity> AddAsync(TEntity entity, bool autoSave = true, CancellationToken cancellationToken = default);


        public Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = true, CancellationToken cancellationToken = default);

        public Task<TEntity?> DeleteAsync(TKey? key, bool autoSave = true, CancellationToken cancellationToken = default);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Task<TEntity?> GetAsync(TKey? key, CancellationToken cancellationToken = default);

        public Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
    }
}
